home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_065 / mwb / mwb_resident.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  6KB  |  220 lines

  1.  
  2. /*
  3.  * MWB_RESIDENT.C
  4.  *
  5.  *  *** Must be compiled with LARGE code and data for manx since this code
  6.  *      will be executed directly from a LoadSeg().  Also must compile with
  7.  *      +B (no .begin statement):       cc +BCDL
  8.  *
  9.  *  *** Make no assumptions as to the initial condition of global data.
  10.  *
  11.  *  signal 0    initial GO signal
  12.  *  signal 1    port signal
  13.  *
  14.  */
  15.  
  16. go()
  17. {
  18.     mwb_resident();
  19.     Wait(0);
  20. }
  21.  
  22. #include "mwb.h"
  23. #include <intuition/intuition.h>
  24. #include <intuition/intuitionbase.h>
  25.  
  26. typedef struct NewScreen NS;
  27. typedef struct Screen    SCR;
  28. typedef struct NewWindow NW;
  29. typedef struct Window   WIN;
  30. typedef struct IntuitionBase IB;
  31.  
  32.  
  33. struct TextAttr Ta = { "topaz.font", 8 };
  34.  
  35. extern char LVOOpenWindow;
  36. extern char LVOCloseWindow;
  37.  
  38. long SysBase;
  39. IB   *IntuitionBase;
  40. long oldopenvec;
  41. long oldclosevec;
  42. short sno;
  43. short uca;
  44. XPORT *Xport;
  45.  
  46.  
  47.  
  48. extern long newopenwindow(), newclosewindow();
  49.  
  50.  
  51. mwb_resident()
  52. {
  53.     register XPORT *xport;
  54.     register XMSG *xmsg;
  55.  
  56.     SysBase = *(long *)4;       /* Get ExecBase                     */
  57.     sno = 0;
  58.     uca = 1;
  59.     Wait(1);                    /* Wait for 'GO' signal from MWB.C  */
  60.     Xport = xport = FindPort(PORT_NAME);/* had better exist                 */
  61.     if (xport) {
  62.         IntuitionBase = (IB *)OpenLibrary("intuition.library", 0);
  63.         oldopenvec = SetFunction(IntuitionBase, &LVOOpenWindow, newopenwindow);
  64.         oldclosevec= SetFunction(IntuitionBase, &LVOCloseWindow,newclosewindow);
  65.         for (;;) {
  66.             WaitPort(xport);    /* wait for message                 */
  67.             xmsg = GetMsg(xport);
  68.             switch(xmsg->com) {
  69.             case OP_QUIT:
  70.                 goto done;
  71.             case OP_CLOSEUNUSED:
  72.                 remscreens();
  73.                 uca = 1;
  74.                 break;
  75.             case OP_NEWSCREEN:
  76.                 for (sno = 0; sno < MAXSCREENS; ++sno) {
  77.                     if (xport->xit[sno].screen == 0) {
  78.                         xport->xit[sno] = xmsg->xit;
  79.                         xport->xit[sno].flags |= FL_DEFINED;
  80.                         uca = 0;
  81.                         break;
  82.                     }
  83.                 }
  84.                 break;
  85.             case OP_SETSCREEN:
  86.                 if (xport->xit[xmsg->screeno].screen) {
  87.                     sno = xmsg->screeno;
  88.                     uca = 0;
  89.                 }
  90.                 break;
  91.             case OP_STARTUP:
  92.                 break;
  93.             }
  94.             xmsg->com = 0;
  95.             ReplyMsg(xmsg);
  96.         }
  97. done:
  98.         xmsg->com = remscreens();
  99.         SetFunction(IntuitionBase, &LVOOpenWindow, oldopenvec);
  100.         SetFunction(IntuitionBase, &LVOCloseWindow,oldclosevec);
  101.         CloseLibrary(IntuitionBase);
  102.         ReplyMsg(xmsg);
  103.         Wait(0);
  104.     }
  105. }
  106.  
  107. remscreens()
  108. {
  109.     register XPORT *xport = Xport;
  110.     register short i;
  111.     register SCR *scr;
  112.     short allnotclosed = 0;
  113.  
  114.     for (i = 1; i < MAXSCREENS; ++i) {
  115.         scr = xport->xit[i].screen;
  116.         if (scr) {
  117.             if (scr->FirstWindow) {
  118.                 allnotclosed = -1;
  119.             } else {
  120.                 CloseScreen(scr);
  121.                 xport->xit[i].screen = NULL;
  122.                 xport->xit[i].flags = 0;
  123.             }
  124.         }
  125.     }
  126.     return(allnotclosed);
  127. }
  128.  
  129.  
  130. /*
  131.  *  LIBRARY INTERCEPT ROUTINES.  NOTE!! Called in context of some other
  132.  *  task.  NOTE!! re-entrant.
  133.  */
  134.  
  135. myopenwindow(nw, cnw)
  136. NW *nw, *cnw;
  137. {
  138.     register XPORT *xport = Xport;
  139.     register XIT *xuse, *xi;
  140.     SCR *scr;
  141.     short i;
  142.     NS Ns;
  143.  
  144.     if ((nw->Type & SCREENTYPE) == WBENCHSCREEN) {
  145.         if (uca) {
  146.             scr = IntuitionBase->ActiveScreen;
  147.             for (i = 0; i < MAXSCREENS; ++i) {
  148.                 if (xport->xit[i].screen == scr) {
  149.                     sno = i;
  150.                     break;
  151.                 }
  152.             }
  153.         }
  154.         xi = xuse = &xport->xit[sno];
  155.         if (xi->screen == NULL) {
  156.             if (!(xi->flags & FL_DEFINED))
  157.                 xuse = &xport->xit[0];
  158.             Ns.LeftEdge = Ns.TopEdge = 0;
  159.             Ns.Width = xuse->width;
  160.             Ns.Height= xuse->height;
  161.             Ns.Depth = xuse->depth;
  162.             Ns.DetailPen = 0;
  163.             Ns.BlockPen = 1;
  164.             Ns.ViewModes = xuse->scrmodes|SPRITES;
  165.             Ns.Type = CUSTOMSCREEN;
  166.             Ns.Font = &Ta;
  167.             Ns.DefaultTitle = xport->scrname;
  168.             Ns.Gadgets = NULL;
  169.             Ns.CustomBitMap = NULL;
  170.             xi->screen = OpenScreen(&Ns);
  171.         }
  172.         if (xi->screen) {
  173.             *cnw = *nw;
  174.             nw = cnw;
  175.             nw->Type = CUSTOMSCREEN;
  176.             nw->Screen = xi->screen;
  177.         }
  178.         uca = 1;
  179.     }
  180.     return(nw);
  181. }
  182.  
  183.  
  184. myclosewindow(win)
  185. WIN *win;
  186. {
  187.     return(win);
  188. }
  189.  
  190.  
  191. #asm
  192.  
  193. _newopenwindow:
  194.                 sub.l   #64,sp
  195.                 move.l  sp,A1               ;pointer to some allocated memory
  196.                 movem.l D2/D3/A4/A6,-(sp)   ;save some registers
  197.                 move.l  A1,-(sp)            ;push ptr to alloc. memory
  198.                 move.l  A0,-(sp)            ;push passed NW argument
  199.                 jsr _myopenwindow           ;call C routine
  200.                 addq.l  #8,sp               ;pop
  201.                 move.l  D0,A0               ;Place return argument into A0
  202.                 move.l  _oldopenvec,A1      ;actual OpenWindow() call
  203.                 movem.l (sp)+,D2/D3/A4/A6   ;restore some registers
  204.                 jsr (A1)                    ;make call
  205.                 add.l   #64,sp              ;deallocate allocated stack
  206.                 rts
  207.  
  208. _newclosewindow:
  209.                 movem.l D2/D3/A4/A6,-(sp)
  210.                 move.l  A0,-(sp)
  211.                 jsr _myclosewindow          ;call with window argument.
  212.                 addq.l  #4,sp
  213.                 move.l  D0,A0
  214.                 move.l  _oldclosevec,A1
  215.                 movem.l (sp)+,D2/D3/A4/A6
  216.                 jmp (A1)
  217.  
  218. #endasm
  219.  
  220.